<template>
    <div id="chater-l-content">
        <div class="chater-l-title">目录</div>
        <div class="go">
            跳转到：<input v-model="chaterInputNum" type="text">
            <div @click="gotoReading(chaterInputNum)">确认</div>
            <div>
                <router-link to = '/'>
                    返回首页
                </router-link>
            </div>
        </div>
        <ul>
            <li 
                v-for="item,index in chaterList"
                :key='bookId+index'
                @click="gotoReading(item.chaterNum)">
                {{item.chaterName}}
            </li>
        </ul>
    </div>
</template>

<script>
export default {
    name: 'chaterList',
    data() {
        return {
            bookId: 9999,
            chaterList: [],
            chaterInputNum: 1,
        }
    },
    methods: {
        gotoReading(n) {
            if(0<n && n<=4){
                this.$router.push({path:'/reading/'+this.bookId+'/'+n+'/must'});
            }
        }
    },
    mounted() {
        this.$axios.get('../static/book'+this.bookId+'-list.json').then((success)=>{
            this.chaterList = success.data;
            console.log(this.chaterList);
        },(err)=>{
            console.log("Oh no! 居然出错了。。。");
        })
    }
}
</script>

<style lang="scss" scoped>
#chater-l-content {
    .chater-l-title {
        padding: 0 15px;
    }
    .go {
        padding: 15px;
        display: flex;
        flex-wrap: wrap;
        font-size: 20px;
        height: 40px;
        line-height: 40px;
        position: sticky;
        top: 0px;
        background-color: #f2f2f2;
        div {
            margin-left: 5px;
            padding: 0 4px;
            background-color: #e2e2e2;
            border: 1px solid black;
            border-radius: 2px;
            font-size: 16px;
        }
        input,div {
            height: 30px;
            line-height: 30px;
            box-sizing: border-box;
            margin-top: 5px;
        }
        input {
            width: 100px;
        }
    }
    li {
        font-size: 18px;
        padding: 15px;
        border-bottom: 1px solid #ccc;
        margin-bottom: 10px;
    }
}
</style>